package com.msmall.community.admin.action;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantUrl;
import com.msmall.community.dpt.model.Department;
import com.msmall.community.dpt.service.DepartmentManager;

public class DepartmentAction extends HTMLBaseAction{

	private static final long serialVersionUID = -5702266464269506290L;
	
	private Long departmentid;
	
	private Department department;
	
	private DepartmentManager departmentManager;

	public String execute(){
		page.setClazz(Department.class);
		page.setPageSize(10);
		departmentManager.getPagination(page);
		page.setUrl(ConstantUrl.ADMIN_DEPARTMENT_INDEX);
		return SUCCESS;
	}
	
	public String create(){
		departmentid = null;
		department = null;
		return SUCCESS;
	}
	public String update(){
		try {
			department = (Department) departmentManager.get(Department.class, departmentid);
		} catch (Exception e) {
			log.debug(e);
		}
		return SUCCESS;
	}

	public String save(){
		try {
			departmentManager.saveDepartment(department, getUserid());
		} catch (Exception e) {
			log.debug(e);
		}
		return SUCCESS;
	}

	public Long getDepartmentid() {
		return departmentid;
	}

	public void setDepartmentid(Long departmentid) {
		this.departmentid = departmentid;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public void setDepartmentManager(DepartmentManager departmentManager) {
		this.departmentManager = departmentManager;
	}
}
